﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace EGNExtractor
{
    class EGNExtractor
    {
        private static List<string> egns = new List<string>();

        public static List<string> Egns
        {
            get { return EGNExtractor.egns; }
        }

        public EGNExtractor()
        {
            egns = new List<string>();
        }

        static void Main()
        {
            string inputFile = "../../persons.txt";
            ReadFile(inputFile);
            foreach (var item in egns)
            {
                Console.WriteLine("EGN: {0}", item);
            }
        }

        private static void ReadFile(string inputFile)
        {
            StreamReader reader = new StreamReader(inputFile);
            using (reader)
            {
                string input = reader.ReadLine();
                while (input != null)
                {
                    ExtractEGN(input);
                    input = reader.ReadLine();
                }
            }
        }

        public static void ExtractEGN(string input)
        {
            Regex patern = new Regex(@"\D(?<egn>[\d]{10})\D");
            Match m = patern.Match(input);
            while (m.Success)
            {
                Group group = m.Groups["egn"];
                egns.Add(group.ToString());
                m = m.NextMatch();
            }
        }
    }
}
